package beans;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

@ManagedBean(name = "contactBean")
@ViewScoped
public class ContactBean {
    private String name;
    private String message;
    private static final String FILESHARE_EMAIL = "al3kopytin@gmail.com";

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void send() {
        try {
            String subject = name + " send message to fileshare!";
            //todo исправить отправку email
            //EmailSender.sendEmail(FILESHARE_EMAIL, subject, message);
            //todo очистка полей бина
            //name = "";
            //message = "";

            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Success", "Your message has been sent!"));

        }
        catch (Exception e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR", e.toString()));
        }
    }
}
